package lab14;

import java.util.Scanner;

public class task2 {

	public static void main(String[] args) {
		int i , j , value;
		int [][] a = new int[4][3];

		Scanner sc = new Scanner(System.in);

		System.out.println("Enter the integar elements of a 3 * 4 2D-array:");

		for(i = 0 ; i < 4 ; i++) {
			for(j = 0 ; j < 3 ; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		System.out.print("Enter the integar value to search for:");
		value = sc.nextInt();

		int [] RowCol = linearSearch2D(a,value);

		if(RowCol[0]==-1)
			System.out.printf("The value %d does not exist in the array.",value);
		else
			System.out.printf("The value %d exists in the array at (row %d , column %d)",value,RowCol[0],RowCol[1]);

		sc.close();

	}


	private static int[] linearSearch2D(int[][] array , int value) {

		int i , j;
		int [] RowCol = {-1 , -1};

		for(i = 0 ; i < 3 ; i++) {
			for(j = 0 ; j < 4 ; j++) {
				if(array[j][i] == value) {
					RowCol[0] = j;
					RowCol[1] = i;
					return RowCol;
				}					
			}
		}
		return RowCol;
	}

}
